package com.ht.baselibs.retrofit.interceptor;

import java.io.IOException;
import java.util.Map;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by huangtao on 16/7/8.
 */
public abstract class PreHeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Map<String, String> headers = getHeaders();
        Request.Builder builder = chain.request()//
                .newBuilder();

        for (Map.Entry<String, String> entry: headers.entrySet()){
            builder.addHeader(entry.getKey(), entry.getValue());
        }


        return chain.proceed(builder.build());
    }

    protected abstract Map<String, String> getHeaders();

}